This invention relates generally to computer programming language compilers, and more particularly to embedding database access statements in the source code submitted to such compilers.
A portion of the disclosure of this patent document contains material which is subject to copyright protection. The copyright owner has no objection to the facsimile reproduction by anyone of the patent document or the patent disclosure as it appears in the Patent and Trademark Office patent file or records, but otherwise reserves all copyright rights whatsoever. The following notice applies to the software and data as described below and in the drawing hereto: Copyright (copyright)2000, Microsoft Corporation, All Rights Reserved.
Many software applications require a database to persistently store data used by the application. As a result, software developers need to design software that interfaces with database software. In general, database management software provides one or both of two types of interfaces, an API (Application Program Interface), or an embedded language style interface.
In the case where the database software interface is through an API, the database management software provides a set of methods (also known as functions) that are called from within the application program software. The methods typically cause the database management system to read, write, and update rows in the database. In addition methods are provided that bind columns to variables, and that provide session and transaction support. The methods typically take parameters that control or modify the behavior of the method, and receive output from the method. It is often the case that a SQL (Structured Query Language) statement will be one of the parameters to a method or function.
In the case of an embedded language interface, the database management system vendor defines a database access language in a grammar that is specific to the vendor. Typically the grammar will support SQL statements. In order to develop software that accesses a database, a software developer embeds statements in the database access language into the source code for the software. Thus, the database access language statements are interspersed with native programming language statements, such as C/C++ statements. The developer must then run what is known as a pre-compiler on the source code. The pre-compiler is a parser application provided by the database management system vendor that is able to parse the embedded statements in the database access grammar. The developer submits the source code file to the pre-compiler. The pre-compiler ignores statements in the native source code and only processes those statements in the database access language. The database language statements are translated into native programming language statements. The original native programming language statements and the statements translated from the database programming language are output to a processed source code file. The processed source code file is then submitted to a native programming language compiler, which produces an object file.
There are significant disadvantages in both of the above-mentioned systems. In the API based system, SQL statements that are provided as parameters must typically be enclosed within quotation marks to avoid the native language compiler from attempting to parse the SQL statement as a native programming language statement. If the statement itself uses quotes, special characters are often required to prevent the compiler from becoming confused by the multiple sets of quotes (one or more in the statement, and the statement enclosing quotes). Furthermore, SQL statements can often be quite long and require multiple lines in the source code. Often the developer must either insert special end of line characters at the end of each line prevent the compiler from terminating the expression prematurely, or attempt to squeeze the statement on a single long line that renders the statement hard to read.
Systems employing the embedded language method also have significant disadvantages. In addition to the problems noted above, the pre-compiler adds complexity to the development process because the developer must remember to invoke the pre-compiler, or must modify scripts to cause the pre-compiler to be invoked. In addition, developers must manage two sets of files, the pre-compiled source code and the translated source code.
Therefore, there is a need in the art for a system that provides a way for developers to embed database language code into native programming language source code files without requiring the use of a pre-compiler.
The above-mentioned shortcomings, disadvantages and problems are addressed by the present invention, which will be understood by reading and studying the following specification.
The present invention includes systems and methods that enable a source code file containing in-line database access statements to be compiled into object code for an application without the use of a pre-compiler. In one aspect of the system, the source code contains delimiters that enclose an attribute section comprising in-line database access statements. The compiler of the system communicates the attribute section to an attribute provider, which translates the attribute section into statements that can be processed by the compiler.
A further aspect of the system is that the attribute provider is a software component. The software component can be a COM (Component Object Model) component.
A still further aspect of the system is that the attribute provider can communicate with a database management system in order to assist in validating the attributes against the tables and columns of the database.